<template>
  <div id="app">
    <!-- 字体图标 -->
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>

    <!-- 顶部 -->
    <TopBar :key="num"></TopBar>
    <!-- 头部 -->
    <Header></Header>
    <!-- 中间可切换内容 -->
    <router-view />
    <!-- 页脚 -->
    <Footer></Footer>
    <!-- 登录模态窗口 -->
    <Login v-show="isShowLoginMadal"></Login>
  </div>
</template>

<script>
import TopBar from "@/components/TopBar.vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import Login from "@/components/Login.vue";
import Toast from "@/components/Toast.vue";
import { JingpinApi } from "@/request/api";
import { mapState } from "vuex";
export default {
  data(){
    return{
      num:0
    }
  },
    watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        // console.log(newVal, oldVal);
        // 执行created里面的代码，更新用户的登录状态，调用回created原本写的代码
        this.num++
      },
    },
  },
  computed: {
    ...mapState({
      isShowLoginMadal: (state) => state.isShowLogin.isShowLoginMadal,
      isShowToast: (state) => state.toastStatus.isShowToast,
    }),
  },
  components: {
    TopBar,
    Header,
    Footer,
    Login,
    Toast,
  },
  created() {
    JingpinApi().then((res) => {
      // console.log(1123213);
      // console.log("请求成功之后的回调函数---组件中的", res);
    });
  },
};
</script>


<style lang="less">
.slide-enter,
.slide-leave-to {
  // 进场的初始状态
  top: -40px;
  opacity: 0;
}
.slide-enter-active,
.slide-leave-active {
  transition: all 1s;
}
.slide-enter-to,
.slide-leave {
  // 进场的最终状态
  top: 0;
  opacity: 1;
}
</style>
